package com.yupi.springbootinit.datasource;


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
@RequiredArgsConstructor
public class DataSourceRegistry {

    private final UserDataSource userDataSource;
    private final PostDataSource postDataSource;
    private final PictureDataSource pictureDataSource;

    private Map<String,DataSource> dataSourceMap = new HashMap<>();

    @PostConstruct
    private void initMap(){
        dataSourceMap.put("post",postDataSource);
        dataSourceMap.put("user",userDataSource);
        dataSourceMap.put("picture",pictureDataSource);
    }

    public DataSource getDataSource(String type){
        return dataSourceMap.get(type);
    }
}
